﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Adams.Public.Web
{
    public class AppendLayoutViewModel
    {
    }

    public class AppendLayoutViewModelAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string token = filterContext.HttpContext.User.Identity.Name;
            string url = filterContext.HttpContext.Request.Url.AbsolutePath;

            var input = new Adams.Public.DataTransfer.Web.Layout.LayoutPageLoadInput() { Token = token, Url = url };
            var model = Business.Web.Layout.PageLoad(input);
            
            filterContext.Controller.ViewBag.Layout = model;
            filterContext.Controller.ViewBag.IsLoggedIn = token.Length > 0;
            filterContext.Controller.ViewBag.FirstName = model.FirstName;
            filterContext.Controller.ViewBag.LastName = model.LastName;
            filterContext.Controller.ViewBag.Email = model.Email;

            base.OnActionExecuting(filterContext);
        }
    }
}